//
//  ZMViewController.m
//  iosClassTool
//
//  Created by 张明磊 on 14-4-3.
//  Copyright (c) 2014年 张明磊. All rights reserved.
//

#import "ZMViewController.h"
#import "MINavigationController.h"
#import "ZINavigationController.h"

@implementation ZMViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self){
        if([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0){
            [self setNeedsStatusBarAppearanceUpdate];
        }
    }
    return self;
}

- (UIStatusBarStyle)preferredStatusBarStyle
{
    return UIStatusBarStyleLightContent;
}

- (BOOL)prefersStatusBarHidden
{
    return NO;
}

- (void)pushViewController:(ZMViewController *)viewController{
    if(IOS7_VERSION){
        [self.navigationController pushViewController:viewController animated:YES];
    }
    else{
        viewController.navigationController_MI = _navigationController_MI;
        viewController.navigationController_ZI = _navigationController_ZI;
        if(_navigationController_MI)
        {
            [_navigationController_MI pushViewController:viewController animated:YES];
        }
        else if(_navigationController_ZI)
        {
            [_navigationController_ZI pushViewController:viewController animated:YES];
        }
    }
}

- (void)popViewController{
    if(IOS7_VERSION){
        [self.navigationController popViewControllerAnimated:YES];
    }
    else{
        if(_navigationController_MI)
        {
            [_navigationController_MI popViewControllerAnimated:YES];
        }
        else if(_navigationController_ZI)
        {
            [_navigationController_ZI popViewControllerAnimated:YES];
        }
    }
}

- (void)popViewControllerToRootView{
    if(IOS7_VERSION){
        [self.navigationController popToRootViewControllerAnimated:YES];
    }
    else{
        if(_navigationController_MI)
        {
            [_navigationController_MI popToRootViewControllerAnimated:YES];
        }
        else if(_navigationController_ZI)
        {
            [_navigationController_ZI popToRootViewControllerAnimated:YES];
        }
    }
}


- (void)handleEventWhenAppGoback{
    //子类实现
}

- (void)handleEventWhenAppGoForeground{
    //子类实现
}

//创建title
- (void)ui_title:(NSString *)titleStr withLeftImageName:(NSString *)leftImageName withReftImageName:(NSString *)rightImageName;
{
    _view_title_super = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 44 + IOS7_SIZE)];
    _view_title_super.backgroundColor = RGB(91, 165, 229);
    [self.view addSubview:_view_title_super];
    
    if (leftImageName) {
        _button_left = [UIButton buttonWithType:UIButtonTypeCustom];
        _button_left.frame = CGRectMake(0, IOS7_SIZE, 60, 45);
        [_button_left setImage:[UIImage imageFileName:leftImageName] forState:UIControlStateNormal];
        [_view_title_super addSubview:_button_left];
    }
    
    _label_title_super = [[UILabel alloc] initWithFrame:CGRectMake(_view_title_super.frame.origin.x,IOS7_SIZE + 5,_view_title_super.frame.size.width,35)];
    _label_title_super.backgroundColor = [UIColor clearColor];
    _label_title_super.textColor = ColorOfTitle;
    _label_title_super.textAlignment = NSTextAlignmentCenter;
    _label_title_super.font = FontOfHelveticaBold(16);
    [_view_title_super addSubview:_label_title_super];
    _label_title_super.text = titleStr;
    
    if (rightImageName) {
        _button_right = [UIButton buttonWithType:UIButtonTypeCustom];
        _button_right.frame = CGRectMake(250, IOS7_SIZE, 60, 45);
        if ([UIImage imageFileName:rightImageName]) {
            [_button_left setImage:[UIImage imageFileName:rightImageName] forState:UIControlStateNormal];
        }
        else
        {
            [_button_right setTitle:rightImageName forState:UIControlStateNormal];
            [_button_right setTitleColor:ColorOfTitle forState:UIControlStateNormal];
            _button_right.titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:15.0f];
        }
        [_view_title_super addSubview:_button_right];
    }
}

@end
